RemoteProcessActivitySetting=function (editor) {
	this.editor = editor;
	this.setting = this.getCurrentAttributeSetting("remote");
};

mxUtils.extend(RemoteProcessActivitySetting, AttributeSetting);

/**
 * 渲染子流程活动属性配置页面
 */
RemoteProcessActivitySetting.prototype.renderRemoteProcessActivitySetting = function() {
	this.renderBasicAttrOfRemoteProcessActivity();
	this.renderParametersOfRemoteProcessActivity();
};

/**
 * 渲染子流程活动的基本属性设置页面
 */
RemoteProcessActivitySetting.prototype.renderBasicAttrOfRemoteProcessActivity = function() {
	var basicAttrRegion = $('#ef_region_basicAttr');
	$('#name', basicAttrRegion)
			.attr('value', this.setting.getAttribute('Name'));
	$('#displayName', basicAttrRegion).attr('value',
			this.setting.getAttribute('DisplayName'));	
	$('#description', basicAttrRegion)
			.attr('value', this.setting.getAttribute('Description'));
	
	var url=$(this.setting).find('Extras>URL')[0];
	var funcId="";
	var soaRemoteTarget="";
	var processDefinitionName="";
	if(url!=null){
	funcId=url.getAttribute('FuncId');
	soaRemoteTarget=url.getAttribute('SoaRemoteTarget');
	processDefinitionName=url.getAttribute('ProcessDefinitionName');
	}
	$('#funcId', basicAttrRegion)
			.attr('value',funcId);
	$('#soaRemoteTarget', basicAttrRegion)
			.attr('value',soaRemoteTarget);
	$('#processDefinitionName', basicAttrRegion).attr('value',processDefinitionName);
};

/**
 * 渲染参数相关参数数据表格
 * 
 * @return
 */
RemoteProcessActivitySetting.prototype.renderParametersOfRemoteProcessActivity = function() {
	var GRIDNAME = "parametersResult";
	var dom = $(this.setting);
	// 构造eiInfo
	var info = new EiInfo();
	var typemeta = new EiBlockMeta('inOutType');
	var typecol1 = new EiColumn('A');
	typecol1.pos = 0;
	typecol1.descName = 'A';

	var typecol2 = new EiColumn('B');
	typecol2.pos = 1;
	typecol2.descName = 'B';
	typemeta.addMeta(typecol1);
	typemeta.addMeta(typecol2);

	var typerow1 = [];
	typerow1.push("I");
	typerow1.push("输入");

	var typerow2 = [];
	typerow2.push("O");
	typerow2.push("输出");

	var typeblock = new EiBlock(typemeta);

	typeblock.addRow(typerow1);
	typeblock.addRow(typerow2);
	
	info.addBlock(typeblock);
	
	//dataType
	var typemeta = new EiBlockMeta('dataType');
	var typecol1 = new EiColumn('A');
	typecol1.pos = 0;
	typecol1.descName = 'A';

	var typecol2 = new EiColumn('B');
	typecol2.pos = 1;
	typecol2.descName = 'B';
	typemeta.addMeta(typecol1);
	typemeta.addMeta(typecol2);

	var typerow1 = [];
	typerow1.push("S");
	typerow1.push("单数据");

	var typerow2 = [];
	typerow2.push("M");
	typerow2.push("多数据");

	

	var typeblock = new EiBlock(typemeta);

	typeblock.addRow(typerow1);
	typeblock.addRow(typerow2);

	info.addBlock(typeblock);

	var meta = new EiBlockMeta(GRIDNAME);
	
	
	

	var col1 = new EiColumn('inOutType');
	col1.pos = 0;
	col1.editor = 'combo';
	col1.descName = '传输方式';
	col1.blockName = 'inOutType';
	col1.valueProperty = 'A'; // Key
	col1.labelProperty = 'B'; // 界面显示
	col1.width = '60';
	col1.readonly= 'true';
	
	var col2 = new EiColumn('name');
	col2.pos = 1;
	col2.descName = '名称';
	col2.labelProperty = 'name';
	col2.valueProperty = '名称';
	col2.width = '200';
	col2.readonly= 'true';
	
	var col3 = new EiColumn('dataType');
	col3.pos = 2;
	col3.editor = 'combo';
	col3.descName = '参数类型';
	col3.blockName = 'dataType';
	col3.valueProperty = 'A'; // Key
	col3.labelProperty = 'B'; // 界面显示
	col3.width = '60';
	col3.readonly= 'true';

	
	
	
	var col4= new EiColumn('desc');
	col4.descName = '描述';
	col4.pos = 3;
	col4.labelProperty = 'desc';
	col4.valueProperty = '描述';
	col4.width = '150';
	col4.readonly= 'true';
	
	
	
	var col5= new EiColumn('value');
	col5.descName = '值';
	col5.pos = 4;
	col5.labelProperty = 'value';
	col5.valueProperty = '值';
	col5.width = '150';

	meta.addMeta(col1);
	meta.addMeta(col2);
	meta.addMeta(col3);
	meta.addMeta(col4);
    meta.addMeta(col5);
	var block = new EiBlock(meta);
	info.addBlock(block);

	// 加载扩展属性数据
	$(dom).find('Parameters>Parameter').each(function() {
				var row = [];
				row.push(this.getAttribute("InOutType"));
				row.push(this.getAttribute("Name"));
				row.push(this.getAttribute("DataType"));
				row.push(this.getAttribute("Desc"));
				row.push(this.getAttribute("Value"));
				block.addRow(row);
			});

	// 绘制grid 
	var eventGrid = this.constructGrid(GRIDNAME, info, "true");
	$(document).ready(function() {
				eventGrid.paint();
			});
	return eventGrid;

};
RemoteProcessActivitySetting.prototype.initLoadParameters = function(funcId) {
	var grid = efform.getGrid("ef_grid_parametersResult");
	var eiinfo = grid.eiinfo;
	var block = eiinfo.getBlock("parametersResult");
	block.rows=[];
	
	var rows = [];
	
	info = new EiInfo();
	info.set('funcId', funcId);
	EiCommunicator.send('EW0128', 'queryFuncParameters', info, {
				onSuccess : function(outInfo) {
					var resultBlock = outInfo.getBlock('result');
					rows = resultBlock.getRows();
				},
				onFail : function(message) {
					// alert(message);
				}
			}, false, false);
	$(rows).each(function() {
					var row = [];
					$(this).each(function() {;
								row.push(this.toString());
							});
					block.addRow(row);
				});	
	grid.refresh(eiinfo);

};

RemoteProcessActivitySetting.prototype.updateRemoteProcessActivitySetting = function() {
	this.updateBasicAtrrOfRemoteProcessActivitySetting();
	this.updateParametersOfRemoteProcessActivitySetting();	
	//this.updateAttributeSetting();
};

/**
 * 保存子流程活动基本属性设置
 */
RemoteProcessActivitySetting.prototype.updateBasicAtrrOfRemoteProcessActivitySetting = function() {
	// 获取活动属性配置
	var basicAttrRegion = $('#ef_region_basicAttr');
	var name = $('#name', basicAttrRegion).attr('value');
	var displayName = $('#displayName', basicAttrRegion).attr('value');
	var description = $('#description', basicAttrRegion).attr('value');
	var processDefinitionName = $('#processDefinitionName', basicAttrRegion).attr('value');
	var funcId = $('#funcId', basicAttrRegion).attr('value'); 
	var soaRemoteTarget = $('#soaRemoteTarget', basicAttrRegion).attr('value');
	// 设置基本属性
	var cas = this.setting;
	cas.setAttribute('Name', name);
	cas.setAttribute('DisplayName', displayName);
	cas.setAttribute('Description', description);
	//cas.setAttribute('FuncId', funcId);
	//设置URL属性
	var doc = this.createXmlDocument();
	var url = $(this.setting).find('Extras>URL')[0];
	if (url == null) {
		url = doc.createElement('URL');
		$(this.setting).find('Extras')[0].appendChild(url);
	} 
	url.setAttribute('FuncId', funcId);
	url.setAttribute('SoaRemoteTarget', soaRemoteTarget);
	url.setAttribute('ProcessDefinitionName', processDefinitionName);
	
};


RemoteProcessActivitySetting.prototype.updateParametersOfRemoteProcessActivitySetting = function() {
	var GRIDNAME = "parametersResult";
	// 设置扩展属性
	var doc = this.createXmlDocument();
	var params = $(this.setting).find('Extras>Parameters')[0];
	if (params == null) {
		params = doc.createElement('Parameters');
		$(this.setting).find('Extras')[0].appendChild(params);
	} else
		$(params).empty();

	var grid = efform.getGrid("ef_grid_" + GRIDNAME);
	var eiinfo = grid.eiinfo;
	var block = eiinfo.getBlock(GRIDNAME);
	var parameter = null;
	if (block.getRows().length > 0)
	
		for (var i = 0; i < block.getRows().length; i++) {
			parameter = doc.createElement('Parameter');
			parameter.setAttribute('InOutType', block.getCell(i, 'inOutType'));
			parameter.setAttribute('Name', block.getCell(i, 'name'));
			parameter.setAttribute('DataType', block.getCell(i,
							'dataType'));
			parameter.setAttribute('Desc', block.getCell(i,
							'desc'));
			parameter.setAttribute('Value', block.getCell(i,
							'value'));
			params.appendChild(parameter);
		}
};